package com.cat.dynamicPlanning02;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/find-good-days-to-rob-the-bank/?envType=problem-list-v2&envId=dynamic-programming
 * @create 2025/11/4 22:36
 * @since JDK17
 */

public class Solution36 {
    public List<Integer> goodDaysToRobBank(int[] security, int time) {
        int n = security.length;
        int[] pre = new int[n], suf = new int[n];
        List<Integer> ans = new ArrayList<>();
        for (int i = 1; i < n; i++) {
            if (security[i] <= security[i - 1]) {
                pre[i] = pre[i - 1] + 1;
            } else {
                pre[i] = 0;
            }
        }
        for (int i = n - 2; i >= 0; i--) {
            if (security[i] <= security[i + 1]) {
                suf[i] = suf[i + 1] + 1;
            } else {
                suf[i] = 0;
            }
        }
        for (int i = 0; i < n; i++) {
            if (pre[i] >= time && suf[i] >= time) {
                ans.add(i);
            }
        }

        return ans;
    }
}
